<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 230px;
            height: 430px;
            border: 1px solid red;
            padding: 10px;
            margin: 50px auto;
            text-align: center;
        }
        div img{
            width: 230px;
            height: 300px;
        }
        input{
            width: 50px;
            height: 20px;
            margin-left: -4px;
            margin-right: -4px;
        }
        button{
            width: 20px;
            height: 24px;
        }
        h4{
            margin-top: 20px;
        }
        h3{
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <div>
        <img src="images/2.jpg" alt="">
        <p>纪梵希 小羊皮口红304</p>
        <h3>￥ 340</h3>
        数量：<button id="btn1">-</button>
        <input type="text" id="txt" value="">
        <button id="btn2">+</button>
        <h4>总价￥：<span id="res">0</span></h4>
    </div>

    <script>
        btn1.onclick = function (){
            if(txt.value <= 0){
                return
            }
            txt.value--
            fn()
        }
        btn2.onclick = function (){
            txt.value++
            fn()
        }
        function fn(){
            res.innerHTML = (340  * txt.value * 1).toFixed(2)
        }
        txt.onchange = fn
    </script>
</body>
</html>